package com.qmerak.dao.impl;

import java.util.List;
import java.util.UUID;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.qmerak.dao.HibernateDao;
import com.qmerak.entity.MemAchievementEntity;
import com.qmerak.entity.MemberEntity;

/**
 * @author Shaohong•Cheng
 * @mail shaohong726@126.com
 * @date 2013-4-21
 * @project TUManager
 */
@Repository
public class MemAchievementDao extends
		HibernateDao<MemAchievementEntity, String> {
	public MemAchievementEntity add(MemAchievementEntity entity) {
		entity.setId(UUID.randomUUID().toString());
		return super.add(entity);
	}

	@SuppressWarnings("unchecked")
	public List<MemAchievementEntity> achievementsOfMem(MemberEntity entity) {
		Session session = this.sessionFactory.openSession();
		List<MemAchievementEntity> list = session
				.createQuery("from MemAchievementEntity where memberID=?")
				.setParameter(0, entity.getId()).list();
		session.close();
		return list;
	}

}
